<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=0,user-scalable=0">
    [#include "/wap/include/static.html"]
    <link rel="stylesheet" href="${path}/resources/wap/css/invest/OperatingLoan.css"/>
</head>
<body>
<!--头部-->
<header>
    <div class="left"   onclick="window.location.href='${path}/wap/member'" >
        <img id="goBack" src="${path}/resources/wap/img/invest/back.png">
    </div>
    <div class="center">
        投标详情
    </div>
</header>
<!--颈部-->
<div class="neck">
    <div class="neck-left">
        <p class="left-top">可投金额 (元)</p>

        <p class="left-bottom">${loan.account-loan.amount_invested}</p>
    </div>
    <div class="neck-center">
        <p class="center-top">年化收益</p>
        <span class="center-bottom1">${loan.apr}</span>
        <span class="center-bottom2">%</span>
    </div>
    <div class="neck-right">
        <p class="right-top">投资金额 (元)</p>

        <p class="right-bottom">${loan.min_account}元起投</p>
    </div>
</div>
<!--选项-->
<div class="choice" id="test">
    <div class="option particulars-head">基础信息</div>
    <div class="option audit-data-head">审核资料</div>
    <div class="option record-headAA">投资记录</div>
</div>

<!--基础信息-->
<div class="particulars">
    <h5 class="">【借款描述】</h5>
  ${loan.content }
</div>
<!--审核资料-->
<div class="audit-data">
[@p2p_loan_img borrowId = loan.id]
    [#list tag_list as img]
        <img src="${img.img}" alt=""/>
    [/#list]
[/@p2p_loan_img]
</div>
<!--投资记录-->
<div class="record hidden">
    <div class="record-head">
        <div class="head-left">投资用户</div>
        <div class="head-center">投资金额</div>
        <div class="head-right">投资时间</div>
    </div>

[@p2p_loan_tender_list borrowId = loan.id]
    [#list tag_list as borrowTender]
        <div class="record-details">
            <div class="details-top">
                <div class="details-left">
                    *${borrowTender.username?substring(0,3)}**
                </div>

                <div class="details-center">
                    ￥${borrowTender.success_money }
                </div>
                <div class="details-right">
                    <p>${p2p_date_format(borrowTender.addtime,"yyyy-MM-dd") }</p>
                </div>
            </div>
            <div class="time">
            ${p2p_date_format(borrowTender.addtime,"HH:mm:ss") }
            </div>
        </div>
    [/#list]
[/@p2p_loan_tender_list]


</div>
<!--立即投标-->
<div class="bid">
    立即投标
</div>
<form method="post" class="layui-form">

    <input type="hidden" value="${loan.id}" id="loanId" name="loanId">
    <input type="hidden" value="${token }" name="token"/>
    <input type="hidden" value="" id="packet_id" name="packet_id">

<div class="alert hidden">
    <div class="alert-head">
        <img src="${path}/resources/wap/img/invest/cancel.png" alt=""/>
    </div>
    <div class="alert-two">
    <label for="start">购买金额:</label>
        <input id="start" type="number" name="account" placeholder="起投金额100元">
    </div>
    <div class="alert-three">
    <div class="coupons">抵用劵:</div>
        <div id="dropdown">
            <div class="input_select">请选择红包抵用券</div>
            <ul>
            [#list redpackets as r]
                <li value="${r.id}"><a href="#" value="${r.id}">满 <span>${r.tender_limit}</span>抵<span>${r.money}</span>元(限定${r.tender_time_limit}月以上1</a></li>
            [/#list]
            </ul>
        </div>
    </div>

    <div class="alert-four">
    <label for="password">交易密码:</label>
        <input id="password" name="payPassword" type="text">
    </div>
    <div class="alert-five">
        <button id="buttons1"  lay-filter="MainForm" lay-submit >立即支付</button>
    </div>
</div>
    </form>
</body>

    <script type="text/javascript">
            layui.use('form', function(){
                var form = layui.form(), $=layui.jquery, layer = layui.layer;
                form.on('submit(MainForm)', function(data){

                    var lowest = Number('${loan.min_account}');
                    var balance = Number('${account.balance}');

                    if (balance <  data.field.account  ||  balance<=0) {
                        layer.msg("您的余额不足，请充值");
                        return false;
                    }

                    if (data.field.account < lowest && lowest > 0) {
                        layer.msg("投标金额不能低于最小限额" + lowest + "元");
                        return false;
                    }

                    var index = layer.load();
                    ajax({
                        url:"${path}/bid/tender",
                        data: data.field,
                        success: function(result){
                            if (result.type == "success") {
                                layer.msg(result.content,function(){  location.href ="${path}/wap/bid/detail/${loan.id}"; });
                            } else {
                                layer.msg(result.content,{icon:2});
                            }
                            layer.close(index);
                        },
                        complete:function(){
                            layer.close(index);
                        }
                    });
                    return false;
                });
            });


    [#--var ins = 0;--]
    [#--function want_tender() {--]
        [#--var account =Number($("#start").val());--]
        [#--var borrowId = $("#borrowId").val();--]
        [#--var lowest = Number(${loan.min_account});--]
        [#--var use_money = Number(${account.balance});--]

        [#--var payPassword = $("#password").val();--]
        [#--var userRedId = $("#redId").val();--]
        [#--var r = /^\+?[1-9][0-9]*$/;--]
        [#--if (account == "") {--]
            [#--//$("#buttons1").css("background","#ff3b0a");--]
            [#--$('#buttons1').attr("disabled", false);--]
            [#--toast("投标金额不能为空");--]


            [#--return false ;--]
        [#--} else if(account%10 != 0){--]
            [#--//$("#buttons1").css("background","#998E8B");--]
            [#--$('#buttons1').attr("disabled", false);--]
            [#--toast("投标金额应为10的整数倍");--]

            [#--return false;--]
        [#--} else if (use_money<account||use_money<=0) {--]
            [#--//$("#buttons1").css("background","#ff3b0a");--]
            [#--$('#buttons1').attr("disabled", false);--]
            [#--if(confirm("您的余额不足，是否去充值")){--]
                [#--window.location.href="/front_recharge/toRecharge.dql?device=app";--]
            [#--}--]

            [#--return;--]
        [#--} else if ((account < lowest) && (lowest > 0)) {--]
            [#--$("#buttons1").css("background","#ff3b0a");--]
            [#--$('#buttons1').attr("disabled", false);--]
            [#--toast("投标金额不能低于最小限额" + lowest + "元");--]

            [#--return false;--]
        [#--}else if(!r.test(account)){--]
            [#--$("#buttons1").css("background","#ff3b0a");--]
            [#--$('#buttons1').attr("disabled", false);--]
            [#--toast("请输入整数");--]


            [#--return false;--]
        [#--}--]
        [#--var index =  layer.open({type: 2});--]
        [#--ajax({--]
            [#--url:"${path}/bid/tender",--]
            [#--data: {--]
                [#--"money":account,--]
                [#--"payPassword" :payPassword,--]
                [#--"packet_id" :userRedId,--]
                [#--"loanId" :borrowId,--]

            [#--},--]
            [#--success: function(result){--]
                [#--if (result.type == "success") {--]
                    [#--toast(result.content);--]


                [#--} else {--]
                    [#--toast(result.content);--]


                [#--}--]
                [#--layer.close(index);--]
            [#--},--]
            [#--complete:function(){--]
                [#--layer.close(index);--]
            [#--}--]
        [#--});--]
    [#--};--]


</script>
<script src="${path}/resources/wap/js/invest/OperatingLoan.js"></script>
</html>